package com.iafme.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.StandardReqDTO;
import com.iafme.dto.res.StandardResDTO;
import com.iafme.model.Standard;
import com.iafme.service.StandardService;
import com.systemframework.annotation.OperateAnnotation;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.enums.BusinessType;
import com.systemframework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/21 21:05
 */
@RestController
@RequestMapping("/standard")
@AllArgsConstructor
public class StandardController implements BaseCommonInterface<StandardReqDTO, StandardResDTO> {

    private final StandardService standardService;

    @OperateAnnotation(businessType = BusinessType.INSERT,name = "全球管理-委员信息")
    @SaCheckPermission("world:standard:add")
    @Override
    public Result<String> save(@Valid StandardReqDTO standardReqDTO) {
        Standard standard = Convert.convert(Standard.class, standardReqDTO);
        standardService.save(standard);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.UPDATE,name = "全球管理-委员信息")
    @SaCheckPermission("world:standard:edit")
    @Override
    public Result<String> update(@Valid StandardReqDTO standardReqDTO) {
        Standard standard = Convert.convert(Standard.class, standardReqDTO);
        standardService.updateById(standard);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.DELETE,name = "全球管理-委员信息")
    @SaCheckPermission("world:standard:delete")
    @Override
    public Result<String> del(Integer id) {
        standardService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<StandardResDTO>> lists(StandardReqDTO standardReqDTO) {
        return Result.successResult(standardService.lists(standardReqDTO));
    }

    @Override
    public Result<StandardResDTO> findById(Integer integer) {
        return null;
    }

    @OperateAnnotation(businessType = BusinessType.BATCHDELETE,name = "全球管理-委员信息")
    @SaCheckPermission("world:standard:delete")
    @Override
    public Result<String> batchDel(List<StandardResDTO> list) {
        List<Integer> ids = list.stream().map(StandardResDTO::getId).collect(Collectors.toList());
        standardService.removeByIds(ids);
        return Result.successResult();
    }
}
